package com.siwei.mes.common.trace;

import com.siwei.mes.common.base.BaseParams;
import org.apache.commons.lang.StringUtils;

/**
 * @Description: 用户session
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2019-05-06
 */
public class UserSessionContext {

    private static ThreadLocal<String> SESSION_LOGIN_ID = new InheritableThreadLocal();

    public static void setLoginId(String userId) {
        SESSION_LOGIN_ID.set(userId);
    }

    public static String getLoginId() {
        String loginId = SESSION_LOGIN_ID.get();
        if (StringUtils.isBlank(loginId)) {
            loginId = BaseParams.USER_ID;
        }
        return loginId;
    }
}
